﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GeneticAlgorithm
{
    public class Brush : ICloneable
    {
        public int A { get; set; }
        public int R { get; set; }
        public int G { get; set; }
        public int B { get; set; }

        public void SetRandom()
        {
            A = Constants.Rand.Next(30, 100);
            R = Constants.Rand.Next(0, 256);
            G = Constants.Rand.Next(0, 256);
            B = Constants.Rand.Next(0, 256);
        }

        public void Mutate(Workarea workarea)
        {
            if (Constants.Rand.NextDouble() <= Constants.MutationBrushAChance)
            {
                A = Constants.Rand.Next(30,100);
                workarea.IsChange = true;
            }

            if (Constants.Rand.NextDouble() <= Constants.MutationBrushRChance)
            {
                R = Constants.Rand.Next(0, 256);
                workarea.IsChange = true;
            }

            if (Constants.Rand.NextDouble() <= Constants.MutationBrushGChance)
            {
                G = Constants.Rand.Next(0, 256);
                workarea.IsChange = true;
            }

            if (Constants.Rand.NextDouble() <= Constants.MutationBrushBChance)
            {
                B = Constants.Rand.Next(0, 256);
                workarea.IsChange = true;
            }
        }

        public object Clone()
        {
            return new Brush
            {
                A = A,
                R = R,
                G = G,
                B = B
            };
        }
    }
}
